package com.shadow.mall.product.controller;

import com.shadow.mall.common.core.JsonResult;
import com.shadow.mall.product.api.ProductApi;
import com.shadow.mall.product.converter.ProductConverter;
import com.shadow.mall.product.domain.dto.ProductSkuDTO;
import com.shadow.mall.product.domain.query.GetProductSkuQuery;
import com.shadow.mall.product.domain.query.ListProductSkuQuery;
import com.shadow.mall.product.domain.vo.ProductSkuVO;
import com.shadow.mall.product.service.ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 
 * @version 1.0
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductSkuService productSkuService;

    @Autowired
    private ProductConverter productConverter;

    @Autowired
    ProductApi productApi;

    /**
     * 根据skuCode查询商品sku信息
     *
     * @param skuCode
     * @return
     */
    @GetMapping("/{skuCode}")
    public ProductSkuVO getProductSkuByCode(@PathVariable("skuCode") String skuCode) {
        ProductSkuDTO productSkuDTO = productSkuService.getProductSkuByCode(skuCode);
        if (productSkuDTO == null) {
            return null;
        }
        return productConverter.convert(productSkuDTO);
    }

    @PostMapping("/listProductSku")
    public JsonResult<List<ProductSkuDTO>> listProductSku(@RequestBody ListProductSkuQuery productSkuQuery){
        return productApi.listProductSku(productSkuQuery);
    }

    @RequestMapping("/getProductSku")
    public JsonResult<ProductSkuDTO> getProductSku(@RequestBody GetProductSkuQuery productSkuQuery ){
        return productApi.getProductSku(productSkuQuery);
    }


}